# -*- coding:utf-8 -*-
__author__ = 'gin.chen'


def calculate(nums):
    equals0, r_set, m_set, l_set = list(), set(), set(), set()
    if len(nums) < 3:
        return None
    else:
        l, m, r, length = 0, 1, 2, len(nums)
        while l < length and m < length:
            if l == length - 2:
                break
            if m == length - 1:
                if nums[l] not in l_set:
                    l_set.add(nums[l])
                    l += 1
                else:
                    l += 2
                m_set.clear()
                m = l + 1
            if r == length:
                if nums[m] not in m_set:
                    m_set.add(nums[m])
                    m += 1
                else:
                    m += 2
                r_set.clear()
                r = m + 1
            while r < length:
                if nums[r] not in r_set:
                    r_set.add(nums[r])
                    if nums[l] + nums[m] + nums[r] == 0:
                        equals0.append([nums[l], nums[m], nums[r]])
                    r += 1
                else:
                    r += 2
    return equals0


if __name__ == '__main__':
    print calculate([-1, 0, 1, 2, -1, -4])
